package com.zmn.plat.services.impl.channel;

import java.util.List;
import java.util.Objects;

import javax.annotation.Resource;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.plat.common.dto.KVDTO;
import com.zmn.plat.model.vo.channel.category.ChannelCategoryUnionVo;
import org.springframework.stereotype.Service;

import com.zmn.plat.common.constant.ProductConsts;
import com.zmn.plat.model.entity.category.ServCategAndCategTwoQuery;
import com.zmn.plat.model.entity.channel.ChannelServiceCategory;
import com.zmn.plat.model.vo.channel.ChannelServiceAreaProductCategoryVo;
import com.zmn.plat.persistence.interfaces.channel.ChannelServiceCategoryDAO;
import com.zmn.plat.services.interfaces.channel.ChannelServiceCategoryService;

/**
 * 渠道服务分类
 *
 * @author xiangjunming
 * @since 2019 /08/19 12:19:07
 */
@Service
public class ChannelServiceCategoryServiceImpl implements ChannelServiceCategoryService {

    @Resource
    private ChannelServiceCategoryDAO channelServiceCategoryDAO;

    @Override
    public ChannelServiceCategory findByKey(Integer id) {
        return channelServiceCategoryDAO.findByKey(id);
    }

    @Override
    public List<KVDTO> listAllCategoryByChannelId(Integer channelId) {

        if (NumberUtil.isNullOrZero(channelId)) {
            return null;
        }
        return channelServiceCategoryDAO.listAllCategoryByChannelId(channelId);
    }

    @Override
    public List<ChannelServiceCategory> listByChannelId(Integer channelId, Integer showType) {
        if (Objects.equals(showType, ProductConsts.ERP_PRODUCT_TYPE)) {
            return channelServiceCategoryDAO.listByChannelId(channelId);
        } else {
            return channelServiceCategoryDAO.listShowCategoryByChannelId(channelId);
        }
    }

    @Override
    public List<ChannelServiceAreaProductCategoryVo> listByChannelIdAndShowType(Integer channelId, Integer showType) {
        return channelServiceCategoryDAO.listByChannelIdAndShowType(channelId, showType);
    }

    @Override
    public List<ServCategAndCategTwoQuery> listServCategAndCategTwoQueryByChannelIdAndShowType(Integer channelId, Integer showType) {
        if (Objects.equals(showType, ProductConsts.ERP_PRODUCT_TYPE)) {
            return channelServiceCategoryDAO.listServCategAndCategTwoQueryByChannelId(channelId);
        } else {
            return channelServiceCategoryDAO.listServCategAndShowCategTwoQueryByChannelId(channelId);
        }
    }

    @Override
    public List<ChannelServiceCategory> listByChannelIdAndServCategId(Integer channelId, Integer servCategId, Integer showType) {
        return channelServiceCategoryDAO.listByChannelIdAndServCategId(channelId, servCategId, showType);
    }

    @Override
    public List<ChannelServiceCategory> listByChannelIdAndCategIdAndShowType(Integer channelId, List<Integer> categIds, Integer showType) {
        return channelServiceCategoryDAO.listByChannelIdAndCategIdAndShowType(channelId, categIds, showType);
    }

    @Override
    public List<Integer> listCategIdByChannelIdAndServCategIdAndCategIds(Integer channelId, Integer servCategId, List<Integer> categIds) {
        return channelServiceCategoryDAO.listCategIdByChannelIdAndServCategIdAndCategIds(channelId, servCategId, categIds);
    }

    @Override
    public List<ChannelCategoryUnionVo> listCategoryUnionVoByChannelIdAndServCategIdList(Integer channelId, List<Integer> servCategIdList) {
        return channelServiceCategoryDAO.listCategoryUnionVoByChannelIdAndServCategIdList(channelId, servCategIdList);
    }

    @Override
    public List<ChannelServiceAreaProductCategoryVo> listCategoryByShowCategList(List<ChannelServiceAreaProductCategoryVo> productCategories) {
        return channelServiceCategoryDAO.listCategoryByShowCategList(productCategories);
    }

    @Override
    public int countAvailableCategoryByChannelId(Integer channelId) {
        return channelServiceCategoryDAO.countAvailableCategoryByChannelId(channelId);
    }

    @Override
    public int updateByKey(ChannelServiceCategory record) {
        return channelServiceCategoryDAO.updateByKey(record);
    }

    @Override
    public int insert(ChannelServiceCategory record) {
        return channelServiceCategoryDAO.insert(record);
    }

    @Override
    public int insertBatch(List<ChannelServiceCategory> list) {
        return channelServiceCategoryDAO.insertBatch(list);
    }

    @Override
    public int deleteByKey(Integer id) {
        return channelServiceCategoryDAO.deleteByKey(id);
    }

    @Override
    public int deleteByChannelId(Integer channelId, Integer showType) {
        return channelServiceCategoryDAO.deleteByChannelId(channelId, showType);
    }

    @Override
    public int deleteByChannelIdAndServiceId(Integer channelId, Integer serviceId, Integer showType) {
        return channelServiceCategoryDAO.deleteByChannelIdAndServiceId(channelId, serviceId, showType);
    }

    @Override
    public void copy(Integer originalChannelId, int targetChannelId, String operator) {

        channelServiceCategoryDAO.copy(originalChannelId, targetChannelId, operator);
    }
}